#region Usings

using System.Data.Entity;
using System.Linq;
using xConnected.Core.Model;

#endregion

namespace xConnected.Data
{
    //NOTE:
    //If you need to implement your own logic/code do it in a partial class,
    //modifications in this file may be overwritten.
    public partial class UserRepository
    {
        public override IQueryable<User> GetAll()
        {
            return DbSet
                .Include(u => u.ExpertProfiles)
                .Include(u => u.CompanyProfiles)
                .Include(u => u.CompanyProfiles.Select(c => c.Positions))
                .Include(u => u.MessageFolders)
                .Include(u => u.MessageFolders.Select(m => m.MessageExpertUsers))
                .Include(u => u.MessageFolders.Select(m => m.MessageCompanyUsers))
                .Include(u => u.MessageFolders.Select(m => m.MessagePositionUsers))
                .Include(u => u.ExpertLists)
                .Include(u => u.CompanyLists)
                .Include(u => u.PositionLists);
        }

        public User GetUserByUsername(string input)
        {
            return DbSet.Include(u => u.CompanyProfiles).Include(u => u.ExpertProfiles).SingleOrDefault(u => u.Username == input);
        }

        public User GetUserByEmail(string input)
        {
            return DbSet.Include(u => u.CompanyProfiles).Include(u => u.ExpertProfiles).SingleOrDefault(u => u.Email == input);
        }
    }
}